source("./functions.R")
dfs <- read_csv("../data/Derived/dataframes_drugs_self_reported.csv.gz")
## Rows: 220368 Columns: 18
## ── Column specification ──────────────────────────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (2): Sex, Drug
## dbl (10): SID, age_delta, Age, packyrs, alcoholintakegpd, PriorMed, bmi, sbp...
## lgl  (6): Hypertension, Obesity, Diabetes Mellitus, CAD, Hyperchol, Heart Fa...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
fits.df <- read_csv("../data/Derived/fits.csv")
## Rows: 248 Columns: 13
## ── Column specification ──────────────────────────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (2): term, Drug
## dbl (10): estimate, std.error, statistic, p.value, conf.low, conf.high, frac...
## lgl  (1): AdditionalMarkers
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
fits.glm <- readRDS("../data/Derived/fits.glm.Rds")

0.1 Characterizing age_delta quartiles

dfs %>% 
  select(SID, Drug, PriorMed) %>% 
  pivot_wider(id_cols=SID,
              names_from=Drug,
              values_from=PriorMed) %>% 
  inner_join(dfs %>% 
               filter(Drug=="Statins") %>% # for example
               select(-Drug, -PriorMed),
               by="SID"
               ) ->
  quartiles.df
(quartiles.df$age_delta %>% 
  quantile(probs=c(0,0.25, .5, .75,1)) -> age_delta.quantiles)
##          0%         25%         50%         75%        100% 
## -32.3968598  -5.2954310   0.1598716   5.3321624  31.8912520
(sprintf("(%.1f, %.1f]",
        age_delta.quantiles %>% head(-1),
        age_delta.quantiles %>% tail(-1)
        ) -> age_delta.quantiles.titles)
## [1] "(-32.4, -5.3]" "(-5.3, 0.2]"   "(0.2, 5.3]"    "(5.3, 31.9]"
age_delta.quantiles %>% tail(-1) -> age_delta.quantiles
quartiles.df %>% 
  mutate(age_delta_cat=case_when(
    age_delta <= age_delta.quantiles[1] ~ names(age_delta.quantiles)[1],
    age_delta <= age_delta.quantiles[2] ~ names(age_delta.quantiles)[2],
    age_delta <= age_delta.quantiles[3] ~ names(age_delta.quantiles)[3],
    T ~ "100%"
  )) -> 
  quartiles.df
quartiles.df %>% 
  mutate(age_delta_cat=factor(age_delta_cat,
                              levels=names(age_delta.quantiles),
                              labels=age_delta.quantiles.titles,
                              ordered=TRUE
         )) ->
  quartiles.df
quartiles.df %>%
  drop_na()%>%
  select(-SID) %>% 
  gtsummary::tbl_summary(
    by=age_delta_cat,
    label  = list(
      age_delta   ~ "Cardiac Age gap",
      CAD ~ "Coronary Artery Disease",
      Hyperchol~"Hypercholesterolemia",
      packyrs~ "Packs year of smoking",
      alcoholintakegpd~ "Alcohol is g/day consumed"
    ),
    missing_text = "Missing",
    digits = list(age_delta ~ c(1, 1),
                  packyrs ~ c(2,1),
                  alcoholintakegpd ~ c(1,1)
                  )
    
  ) %>%
  gtsummary::add_p()
Characteristic (-32.4, -5.3], N = 6,8871 (-5.3, 0.2], N = 6,8861 (0.2, 5.3], N = 6,8861 (5.3, 31.9], N = 6,8871 p-value2
Diuretics 252 (3.7%) 316 (4.6%) 314 (4.6%) 348 (5.1%) <0.001
CCB 543 (7.9%) 737 (11%) 742 (11%) 752 (11%) <0.001
ARB 339 (4.9%) 383 (5.6%) 452 (6.6%) 468 (6.8%) <0.001
ACEi 520 (7.6%) 627 (9.1%) 599 (8.7%) 666 (9.7%) <0.001
BB 480 (7.0%) 499 (7.2%) 491 (7.1%) 448 (6.5%) 0.3
Digoxin 8 (0.1%) 8 (0.1%) 9 (0.1%) 11 (0.2%) 0.9
Metformin 189 (2.7%) 232 (3.4%) 244 (3.5%) 302 (4.4%) <0.001
Statins 1,498 (22%) 1,686 (24%) 1,840 (27%) 1,670 (24%) <0.001
Cardiac Age gap -9.0 (-11.9, -7.0) -2.5 (-3.9, -1.1) 2.6 (1.4, 3.9) 8.7 (6.9, 11.3) <0.001
Sex <0.001
Female 3,681 (53%) 3,477 (50%) 3,395 (49%) 3,284 (48%)
Male 3,206 (47%) 3,409 (50%) 3,491 (51%) 3,603 (52%)
Age 63 (56, 69) 65 (58, 71) 66 (60, 71) 64 (59, 69) <0.001
Packs year of smoking 0.00 (0.0, 1.16) 0.00 (0.0, 3.00) 0.00 (0.0, 3.75) 0.00 (0.0, 4.50) <0.001
Alcohol is g/day consumed 3.2 (0.0, 14.2) 3.8 (0.0, 15.2) 4.1 (0.0, 16.6) 3.4 (0.0, 15.3) <0.001
Hypertension 1,742 (25%) 2,266 (33%) 2,448 (36%) 2,742 (40%) <0.001
Obesity 1,497 (22%) 1,380 (20%) 1,416 (21%) 1,382 (20%) 0.047
Diabetes Mellitus 432 (6.3%) 474 (6.9%) 502 (7.3%) 575 (8.3%) <0.001
Coronary Artery Disease 487 (7.1%) 549 (8.0%) 564 (8.2%) 508 (7.4%) 0.049
Hypercholesterolemia 1,418 (21%) 1,582 (23%) 1,700 (25%) 1,591 (23%) <0.001
Heart Failure 96 (1.4%) 107 (1.6%) 97 (1.4%) 112 (1.6%) 0.6
bmi 26.1 (23.6, 29.4) 26.2 (23.7, 29.3) 26.3 (23.9, 29.2) 26.5 (24.0, 29.3) 0.003
sbp 131 (120, 143) 137 (126, 150) 140 (129, 153) 142 (131, 156) <0.001
dbp 76 (69, 82) 78 (72, 84) 80 (73, 86) 82 (75, 89) <0.001
pulse_rate 66 (58, 73) 67 (60, 76) 68 (61, 76) 71 (64, 79) <0.001
1 n (%); Median (IQR)
2 Pearson's Chi-squared test; Kruskal-Wallis rank sum test
quartiles.df %>%
  select(age_delta_cat,
         Diuretics,
         CCB,
         ARB,
         ACEi,
         BB,
         Digoxin,
         Metformin,
         Statins,
         Sex,
         Age,
         age_delta
         ) %>% 
  drop_na()%>%
  gtsummary::tbl_summary(
    by=age_delta_cat,
    label  = list(
      age_delta   ~ "Cardiac Age gap"
    ),
    missing_text = "Missing",
    digits = list(age_delta ~ c(1, 1)
                  )
    
  ) %>%
  gtsummary::add_p()
Characteristic (-32.4, -5.3], N = 6,8871 (-5.3, 0.2], N = 6,8861 (0.2, 5.3], N = 6,8861 (5.3, 31.9], N = 6,8871 p-value2
Diuretics 252 (3.7%) 316 (4.6%) 314 (4.6%) 348 (5.1%) <0.001
CCB 543 (7.9%) 737 (11%) 742 (11%) 752 (11%) <0.001
ARB 339 (4.9%) 383 (5.6%) 452 (6.6%) 468 (6.8%) <0.001
ACEi 520 (7.6%) 627 (9.1%) 599 (8.7%) 666 (9.7%) <0.001
BB 480 (7.0%) 499 (7.2%) 491 (7.1%) 448 (6.5%) 0.3
Digoxin 8 (0.1%) 8 (0.1%) 9 (0.1%) 11 (0.2%) 0.9
Metformin 189 (2.7%) 232 (3.4%) 244 (3.5%) 302 (4.4%) <0.001
Statins 1,498 (22%) 1,686 (24%) 1,840 (27%) 1,670 (24%) <0.001
Sex <0.001
Female 3,681 (53%) 3,477 (50%) 3,395 (49%) 3,284 (48%)
Male 3,206 (47%) 3,409 (50%) 3,491 (51%) 3,603 (52%)
Age 63 (56, 69) 65 (58, 71) 66 (60, 71) 64 (59, 69) <0.001
Cardiac Age gap -9.0 (-11.9, -7.0) -2.5 (-3.9, -1.1) 2.6 (1.4, 3.9) 8.7 (6.9, 11.3) <0.001
1 n (%); Median (IQR)
2 Pearson's Chi-squared test; Kruskal-Wallis rank sum test

0.2 Correlation of features

quartiles.df %>% 
  select(-SID,
         -age_delta_cat
         ) %>% 
  mutate(Male=if_else(Sex=="Male", 1, 0)) %>% 
  select(-Sex) %>% 
  mutate_all(as.double) %>% 
  as.matrix()->
  X
Hmisc::rcorr(X, type="pearson") -> cor.pearson
cor.pearson$r -> M
corrplot::corrplot( M,
                   method="ellipse",
                   type="lower",
                   na.label='-', 
                   tl.cex = 0.7, 
                   order="AOE",
                   tl.col="black",
                   tl.srt=45,
                   number.cex = 0.3) 

corrplot::corrplot( M,
                   method="ellipse",
                   type="lower",
                   na.label='-', 
                   tl.cex = 0.7, 
                   order="hclust",
                   tl.col="black",
                   tl.srt=45,
                   number.cex = 0.3) 

0.3 Medication-Effect Overview

0.3.1 Forest plot

(fits.df  %>% 
  filter(term=="PriorMed") %>% 
  mutate(Adjustment=if_else(AdditionalMarkers==TRUE, "With SBP/DBP/HR", "Without SBP/DBP/HR")) %>% 
  mutate(Adjustment=factor(Adjustment, levels=c("Without SBP/DBP/HR","With SBP/DBP/HR"), ordered=TRUE)) %>% 
  ggplot(aes(x=Drug, y=estimate, ymin=conf.low, ymax=conf.high, color=Adjustment))+
  geom_point( position=position_dodge(width=0.3))+
  geom_linerange( position=position_dodge(width=0.3))+
  coord_flip()+
  xlab("Drug")+
  ylab("Coefficient")+
  geom_hline(yintercept=0, alpha=0.5, linetype="dashed")+
  scale_color_manual(values = c("Without SBP/DBP/HR" = "red",
                                    "With SBP/DBP/HR" = "forestgreen"
                                    )) -> p)

p+geom_segment(aes(y = 0.05, x = .55, yend = 3, xend = .55),
                  arrow = arrow(length = unit(0.25, "cm")), show.legend=FALSE, color="black")+
    geom_text(aes(y = 1.5, x = .725, label = "Drug increases cardiac age gap"), size=3, color="black") +
geom_segment(aes(y = -0.05, x = .55, yend = -3, xend = .55),
                  arrow = arrow(length = unit(0.25, "cm")), show.legend=FALSE, color="black")+
    geom_text(aes(y = -1.5, x = .725, label = "Drug decreases cardiac age gap"), size=3, color="black")

(fits.df  %>% 
  filter(term=="PriorMed") %>% 
  filter(AdditionalMarkers==TRUE) %>% 
  ggplot(aes(x=Drug, y=estimate, ymin=conf.low, ymax=conf.high))+
  geom_point( )+
  geom_linerange()+
  coord_flip()+
  xlab("Drug")+
  ylab("Coefficient")+
  geom_hline(yintercept=0, alpha=0.5, linetype="dashed") -> p)

fits.df  %>% 
  filter(term=="PriorMed") %>% 
  filter(AdditionalMarkers==TRUE) %>% 
  mutate(n=round(fracPriorMed*nobs)) ->
  phewas_results

plot_data <- phewas_results %>%
    dplyr::select(Drug, p.value, estimate, conf.high, conf.low, n) %>%
    dplyr::mutate(p.value.str=sprintf("%.3f", p.value), beta.str=sprintf("%.2f", estimate))

  parm <- plot_data %>% dplyr::mutate(mean=estimate,lower=conf.low,upper=conf.high) %>%
    dplyr::select(mean, lower, upper)
  parm <- rbind(rep(NA,3), parm)

  labeltext <- plot_data %>% dplyr::select(Drug, n, beta.str, p.value.str)
  if (nrow(labeltext)>1) {
    labeltext <- as.matrix(sapply(labeltext, as.character))
  }
  labeltext <- rbind(c('Drug','N', 'Coefficient', 'P-Value'), labeltext)
fig_width <- 8
forestplot::forestplot(labeltext=labeltext, 
                       parm, 
                       zero=0, 
                       xlab='Coefficient',
                       title = "Medication Effects", 
                       is.summary=c(TRUE, rep(FALSE, nrow(plot_data))) ,
                       txt_gp=forestplot::fpTxtGp(ticks=gpar(cex=1.2),xlab=gpar(cex=1.5), title = gpar(cex=2.0), cex=1.2), 
                       graph.pos = 4,
                       graphwidth = grid::unit(fig_width,"cm"), 
                       lwd.zero=3, 
                       lwd.ci=3)

0.3.2 Table

fits.df  %>% 
  filter(term=="PriorMed") %>% 
  mutate(Adjustment=if_else(AdditionalMarkers==TRUE, "With SBP/DBP/HR", "Without SBP/DBP/HR")) %>% 
  mutate(Adjustment=factor(Adjustment, levels=c("Without SBP/DBP/HR","With SBP/DBP/HR"), ordered=TRUE)) %>% 
  transmute(Drug,Adjustment, estimate, std.error, statistic, p.value, conf.low, conf.high) %>% 
  mutate(across(.cols=estimate:conf.high, ~round(.,2)))->table1
table1 %>% 
  kbl(caption = "Table S1: Coefficients of self-reported drugs") %>%
  kable_classic(full_width = F, html_font = "Cambria")
Table S1: Coefficients of self-reported drugs
Drug Adjustment estimate std.error statistic p.value conf.low conf.high
Diuretics With SBP/DBP/HR 0.11 0.22 0.51 0.61 -0.32 0.55
Diuretics Without SBP/DBP/HR -0.29 0.23 -1.25 0.21 -0.74 0.16
CCB With SBP/DBP/HR -0.34 0.16 -2.08 0.04 -0.66 -0.02
CCB Without SBP/DBP/HR -0.69 0.17 -4.05 0.00 -1.02 -0.35
ARB With SBP/DBP/HR 0.18 0.20 0.94 0.35 -0.20 0.57
ARB Without SBP/DBP/HR -0.06 0.20 -0.29 0.77 -0.46 0.34
ACEi With SBP/DBP/HR -0.04 0.17 -0.26 0.79 -0.37 0.29
ACEi Without SBP/DBP/HR -0.42 0.18 -2.39 0.02 -0.76 -0.08
BB With SBP/DBP/HR 0.61 0.19 3.18 0.00 0.23 0.98
BB Without SBP/DBP/HR -0.82 0.20 -4.17 0.00 -1.20 -0.43
Digoxin With SBP/DBP/HR 0.55 1.21 0.45 0.65 -1.83 2.92
Digoxin Without SBP/DBP/HR 0.82 1.27 0.64 0.52 -1.67 3.30
Metformin With SBP/DBP/HR 0.80 0.33 2.46 0.01 0.16 1.44
Metformin Without SBP/DBP/HR 0.95 0.34 2.80 0.01 0.29 1.62
Statins With SBP/DBP/HR 0.11 0.14 0.82 0.41 -0.16 0.38
Statins Without SBP/DBP/HR -0.25 0.14 -1.78 0.07 -0.53 0.03
fits.df  %>% 
  filter(term=="PriorMed") %>% 
  filter(AdditionalMarkers==TRUE) %>% 
  select(-AdditionalMarkers) %>% 
  transmute(Drug, estimate, std.error, statistic, p.value, conf.low, conf.high) %>% 
  mutate(across(.cols=estimate:conf.high, ~round(.,2))) -> table2
table2 %>% 
  kbl(caption = "Table 1: Coefficients of self-reported drugs") %>%
  kable_classic(full_width = F, html_font = "Cambria")
Table 1: Coefficients of self-reported drugs
Drug estimate std.error statistic p.value conf.low conf.high
Diuretics 0.11 0.22 0.51 0.61 -0.32 0.55
CCB -0.34 0.16 -2.08 0.04 -0.66 -0.02
ARB 0.18 0.20 0.94 0.35 -0.20 0.57
ACEi -0.04 0.17 -0.26 0.79 -0.37 0.29
BB 0.61 0.19 3.18 0.00 0.23 0.98
Digoxin 0.55 1.21 0.45 0.65 -1.83 2.92
Metformin 0.80 0.33 2.46 0.01 0.16 1.44
Statins 0.11 0.14 0.82 0.41 -0.16 0.38

0.4 Statins

statin.df <- dfs %>% 
  filter(Drug=="Statins") %>% 
  select(-Drug)
statin.fits.df <- fits.df %>% 
  filter(Drug=="Statins")
get_pretty_fit_table(statin.fits.df, "Statins")
Statins: Coefficients from linear models
term estimate std.error statistic p.value conf.low conf.high Adjustment
(Intercept) -20.526 0.517 -39.703 0.000 -21.539 -19.512 With SBP/DBP/HR
(Intercept) -0.876 0.359 -2.437 0.015 -1.580 -0.171 Without SBP/DBP/HR
Diabetes MellitusTRUE 0.645 0.178 3.628 0.000 0.297 0.994 With SBP/DBP/HR
Diabetes MellitusTRUE 0.649 0.185 3.510 0.000 0.287 1.012 Without SBP/DBP/HR
Heart FailureTRUE 0.107 0.370 0.288 0.773 -0.619 0.832 With SBP/DBP/HR
Heart FailureTRUE -0.125 0.387 -0.323 0.746 -0.885 0.634 Without SBP/DBP/HR
alcoholintakegpd 0.001 0.003 0.328 0.743 -0.004 0.006 With SBP/DBP/HR
alcoholintakegpd 0.006 0.003 2.325 0.020 0.001 0.011 Without SBP/DBP/HR
bmi -0.147 0.014 -10.553 0.000 -0.175 -0.120 With SBP/DBP/HR
bmi 0.000 0.014 -0.002 0.999 -0.028 0.028 Without SBP/DBP/HR
CADTRUE 0.438 0.178 2.461 0.014 0.089 0.786 With SBP/DBP/HR
CADTRUE -0.440 0.185 -2.381 0.017 -0.803 -0.078 Without SBP/DBP/HR
dbp 0.087 0.006 14.002 0.000 0.075 0.100 With SBP/DBP/HR
HypercholTRUE -0.198 0.132 -1.497 0.134 -0.458 0.061 With SBP/DBP/HR
HypercholTRUE -0.095 0.138 -0.684 0.494 -0.366 0.177 Without SBP/DBP/HR
HypertensionTRUE 0.646 0.103 6.298 0.000 0.445 0.846 With SBP/DBP/HR
HypertensionTRUE 1.838 0.104 17.683 0.000 1.634 2.042 Without SBP/DBP/HR
ObesityTRUE -0.255 0.148 -1.722 0.085 -0.546 0.035 With SBP/DBP/HR
ObesityTRUE -0.741 0.155 -4.786 0.000 -1.044 -0.437 Without SBP/DBP/HR
packyrs 0.023 0.004 6.029 0.000 0.015 0.030 With SBP/DBP/HR
packyrs 0.022 0.004 5.499 0.000 0.014 0.030 Without SBP/DBP/HR
poly(Age, 2)1 -69.744 8.444 -8.260 0.000 -86.294 -53.194 With SBP/DBP/HR
poly(Age, 2)1 -22.395 8.031 -2.788 0.005 -38.137 -6.653 Without SBP/DBP/HR
poly(Age, 2)2 -106.586 7.248 -14.705 0.000 -120.793 -92.378 With SBP/DBP/HR
poly(Age, 2)2 -112.960 7.565 -14.932 0.000 -127.787 -98.132 Without SBP/DBP/HR
PriorMed 0.112 0.137 0.818 0.414 -0.156 0.380 With SBP/DBP/HR
PriorMed -0.254 0.143 -1.781 0.075 -0.534 0.026 Without SBP/DBP/HR
pulse_rate 0.110 0.004 27.855 0.000 0.103 0.118 With SBP/DBP/HR
sbp 0.067 0.003 19.643 0.000 0.061 0.074 With SBP/DBP/HR
SexMale 0.442 0.095 4.648 0.000 0.256 0.629 With SBP/DBP/HR
SexMale 0.540 0.096 5.593 0.000 0.351 0.729 Without SBP/DBP/HR
get_pretty_fit_forest_plot(statin.fits.df) ->p
p

statin.fits.df %>% 
  get_fit_glance
generate_table.self.reported(statin.df, "Statins")
Characteristic No Statins, N = 20,8521 Statins, N = 6,6941 p-value2
Cardiac Age gap 0.0 (-5.5, 5.3) 0.6 (-4.6, 5.3) <0.001
Sex <0.001
Female 11,672 (56%) 2,165 (32%)
Male 9,180 (44%) 4,529 (68%)
Age 63 (57, 68) 69 (64, 72) <0.001
Packs year of smoking 0 (0, 1) 0 (0, 8) <0.001
Alcohol is g/day consumed 3 (0, 14) 4 (0, 18) <0.001
Hypertension 5,419 (26%) 3,779 (56%) <0.001
Obesity 3,889 (19%) 1,786 (27%) <0.001
Diabetes Mellitus 770 (3.7%) 1,213 (18%) <0.001
Coronary Artery Disease 727 (3.5%) 1,381 (21%) <0.001
Hypercholesterolemia 1,711 (8.2%) 4,580 (68%) <0.001
Heart Failure 190 (0.9%) 222 (3.3%) <0.001
dbp 78 (72, 86) 78 (72, 85) 0.12
sbp 136 (125, 150) 142 (130, 154) <0.001
pulse_rate 68 (61, 76) 68 (60, 76) 0.054
bmi 25.9 (23.5, 28.9) 27.3 (24.9, 30.3) <0.001
1 Median (IQR); n (%)
2 Wilcoxon rank sum test; Pearson's Chi-squared test
statin.df %>% 
  get_stratified_age_gap_histogram("Statins")

statin.df %>% 
  get_stratified_age_gap_quantiles("Statins")

0.4.1 Lasso

statin.glmnet.cv <- fits.glm[["Statins"]]
plot(statin.glmnet.cv) 

coef(statin.glmnet.cv, c(statin.glmnet.cv$lambda.min,
                   statin.glmnet.cv$lambda.1se))
## 17 x 2 sparse Matrix of class "dgCMatrix"
##                                    s1            s2
## (Intercept)             -2.275099e-16 -1.080653e-16
## SID                      6.956339e-04  .           
## SexMale                  2.260680e-02  .           
## Age                     -4.736318e-02  .           
## packyrs                  3.460619e-02  7.207680e-03
## alcoholintakegpd         2.768395e-03  .           
## PriorMed                 .             .           
## HypertensionTRUE         3.887463e-02  1.273594e-02
## ObesityTRUE             -9.817050e-03  .           
## `Diabetes Mellitus`TRUE  1.989265e-02  .           
## CADTRUE                  1.123753e-02  .           
## HypercholTRUE           -5.070867e-03  .           
## `Heart Failure`TRUE      .             .           
## bmi                     -8.337809e-02 -3.636707e-02
## sbp                      1.542788e-01  1.182037e-01
## dbp                      1.232901e-01  1.244400e-01
## pulse_rate               1.640762e-01  1.306085e-01

0.5 Metformin

metformin.df <- dfs %>% 
  filter(Drug=="Metformin") %>% 
  select(-Drug)
metformin.fits.df <- fits.df %>% 
  filter(Drug=="Metformin")
get_pretty_fit_table(metformin.fits.df, "Metformin")
Metformin: Coefficients from linear models
term estimate std.error statistic p.value conf.low conf.high Adjustment
(Intercept) -20.492 0.517 -39.642 0.000 -21.505 -19.479 With SBP/DBP/HR
(Intercept) -0.839 0.359 -2.336 0.019 -1.543 -0.135 Without SBP/DBP/HR
Diabetes MellitusTRUE 0.286 0.234 1.218 0.223 -0.174 0.745 With SBP/DBP/HR
Diabetes MellitusTRUE 0.150 0.245 0.612 0.541 -0.330 0.630 Without SBP/DBP/HR
Heart FailureTRUE 0.114 0.370 0.308 0.758 -0.612 0.840 With SBP/DBP/HR
Heart FailureTRUE -0.117 0.387 -0.302 0.763 -0.876 0.642 Without SBP/DBP/HR
alcoholintakegpd 0.001 0.003 0.376 0.707 -0.004 0.006 With SBP/DBP/HR
alcoholintakegpd 0.006 0.003 2.389 0.017 0.001 0.012 Without SBP/DBP/HR
bmi -0.147 0.014 -10.550 0.000 -0.174 -0.120 With SBP/DBP/HR
bmi -0.001 0.014 -0.104 0.918 -0.029 0.026 Without SBP/DBP/HR
CADTRUE 0.461 0.176 2.615 0.009 0.116 0.807 With SBP/DBP/HR
CADTRUE -0.478 0.183 -2.611 0.009 -0.838 -0.119 Without SBP/DBP/HR
dbp 0.088 0.006 14.052 0.000 0.075 0.100 With SBP/DBP/HR
HypercholTRUE -0.147 0.112 -1.317 0.188 -0.367 0.072 With SBP/DBP/HR
HypercholTRUE -0.236 0.117 -2.019 0.044 -0.465 -0.007 Without SBP/DBP/HR
HypertensionTRUE 0.652 0.102 6.405 0.000 0.453 0.852 With SBP/DBP/HR
HypertensionTRUE 1.815 0.103 17.561 0.000 1.612 2.018 Without SBP/DBP/HR
ObesityTRUE -0.270 0.148 -1.818 0.069 -0.560 0.021 With SBP/DBP/HR
ObesityTRUE -0.753 0.155 -4.863 0.000 -1.056 -0.449 Without SBP/DBP/HR
packyrs 0.023 0.004 6.018 0.000 0.015 0.030 With SBP/DBP/HR
packyrs 0.021 0.004 5.418 0.000 0.014 0.029 Without SBP/DBP/HR
poly(Age, 2)1 -68.470 8.356 -8.194 0.000 -84.849 -52.091 With SBP/DBP/HR
poly(Age, 2)1 -24.417 7.936 -3.077 0.002 -39.971 -8.862 Without SBP/DBP/HR
poly(Age, 2)2 -106.349 7.246 -14.676 0.000 -120.552 -92.146 With SBP/DBP/HR
poly(Age, 2)2 -113.168 7.562 -14.965 0.000 -127.991 -98.346 Without SBP/DBP/HR
PriorMed 0.799 0.325 2.456 0.014 0.161 1.437 With SBP/DBP/HR
PriorMed 0.952 0.340 2.799 0.005 0.285 1.618 Without SBP/DBP/HR
pulse_rate 0.110 0.004 27.703 0.000 0.102 0.118 With SBP/DBP/HR
sbp 0.067 0.003 19.608 0.000 0.061 0.074 With SBP/DBP/HR
SexMale 0.442 0.095 4.668 0.000 0.256 0.628 With SBP/DBP/HR
SexMale 0.515 0.096 5.370 0.000 0.327 0.704 Without SBP/DBP/HR
get_pretty_fit_forest_plot(metformin.fits.df) ->p
p

metformin.fits.df %>% 
  get_fit_glance
generate_table.self.reported(metformin.df, "Metformin")
Characteristic Metformin, N = 9671 No Metformin, N = 26,5791 p-value2
Cardiac Age gap 1.4 (-3.7, 6.8) 0.1 (-5.4, 5.3) <0.001
Sex <0.001
Female 299 (31%) 13,538 (51%)
Male 668 (69%) 13,041 (49%)
Age 66 (60, 71) 64 (58, 70) <0.001
Packs year of smoking 0 (0, 13) 0 (0, 3) <0.001
Alcohol is g/day consumed 1 (0, 11) 4 (0, 15) <0.001
Hypertension 630 (65%) 8,568 (32%) <0.001
Obesity 541 (56%) 5,134 (19%) <0.001
Diabetes Mellitus 967 (100%) 1,016 (3.8%) <0.001
Coronary Artery Disease 174 (18%) 1,934 (7.3%) <0.001
Hypercholesterolemia 516 (53%) 5,775 (22%) <0.001
Heart Failure 38 (3.9%) 374 (1.4%) <0.001
dbp 78 (71, 84) 78 (72, 86) 0.005
sbp 140 (130, 153) 138 (126, 150) <0.001
pulse_rate 73 (65, 83) 68 (60, 76) <0.001
bmi 29.7 (26.7, 33.5) 26.2 (23.7, 29.1) <0.001
1 Median (IQR); n (%)
2 Wilcoxon rank sum test; Pearson's Chi-squared test
metformin.df %>% 
  get_stratified_age_gap_histogram("Metformin")

metformin.df %>% 
    get_stratified_age_gap_quantiles("Metformin")

0.5.1 Lasso

metformin.glmnet.cv <- fits.glm[["Metformin"]]
plot(metformin.glmnet.cv) 

coef(metformin.glmnet.cv, c(metformin.glmnet.cv$lambda.min,
                   metformin.glmnet.cv$lambda.1se))
## 17 x 2 sparse Matrix of class "dgCMatrix"
##                                    s1            s2
## (Intercept)             -1.919073e-16 -1.144220e-16
## SID                      1.997608e-03  .           
## SexMale                  2.326247e-02  .           
## Age                     -4.960966e-02 -3.901188e-04
## packyrs                  3.571725e-02  1.000863e-02
## alcoholintakegpd         3.916300e-03  .           
## PriorMed                 1.948702e-02  .           
## HypertensionTRUE         4.019460e-02  1.517539e-02
## ObesityTRUE             -1.121007e-02  .           
## `Diabetes Mellitus`TRUE  8.450938e-03  .           
## CADTRUE                  1.318581e-02  .           
## HypercholTRUE           -7.544698e-03  .           
## `Heart Failure`TRUE      1.049425e-04  .           
## bmi                     -8.587474e-02 -4.076007e-02
## sbp                      1.559864e-01  1.195392e-01
## dbp                      1.237520e-01  1.262449e-01
## pulse_rate               1.652048e-01  1.331395e-01

0.6 Digoxin

digoxin.df <- dfs %>% 
  filter(Drug=="Digoxin") %>% 
  select(-Drug)
digoxin.fits.df <- fits.df %>% 
  filter(Drug=="Digoxin")
get_pretty_fit_table(digoxin.fits.df, "Digoxin")
Digoxin: Coefficients from linear models
term estimate std.error statistic p.value conf.low conf.high Adjustment
(Intercept) -20.518 0.517 -39.695 0.000 -21.531 -19.504 With SBP/DBP/HR
(Intercept) -0.858 0.359 -2.390 0.017 -1.562 -0.154 Without SBP/DBP/HR
Diabetes MellitusTRUE 0.662 0.176 3.755 0.000 0.317 1.008 With SBP/DBP/HR
Diabetes MellitusTRUE 0.601 0.183 3.276 0.001 0.241 0.960 Without SBP/DBP/HR
Heart FailureTRUE 0.088 0.372 0.237 0.813 -0.642 0.818 With SBP/DBP/HR
Heart FailureTRUE -0.152 0.390 -0.391 0.696 -0.916 0.611 Without SBP/DBP/HR
alcoholintakegpd 0.001 0.003 0.323 0.747 -0.004 0.006 With SBP/DBP/HR
alcoholintakegpd 0.006 0.003 2.328 0.020 0.001 0.011 Without SBP/DBP/HR
bmi -0.147 0.014 -10.522 0.000 -0.174 -0.119 With SBP/DBP/HR
bmi -0.001 0.014 -0.072 0.942 -0.029 0.027 Without SBP/DBP/HR
CADTRUE 0.458 0.176 2.594 0.009 0.112 0.803 With SBP/DBP/HR
CADTRUE -0.483 0.183 -2.637 0.008 -0.842 -0.124 Without SBP/DBP/HR
dbp 0.087 0.006 13.981 0.000 0.075 0.099 With SBP/DBP/HR
HypercholTRUE -0.140 0.112 -1.250 0.211 -0.359 0.079 With SBP/DBP/HR
HypercholTRUE -0.226 0.117 -1.936 0.053 -0.456 0.003 Without SBP/DBP/HR
HypertensionTRUE 0.655 0.102 6.429 0.000 0.455 0.854 With SBP/DBP/HR
HypertensionTRUE 1.818 0.103 17.584 0.000 1.615 2.020 Without SBP/DBP/HR
ObesityTRUE -0.257 0.148 -1.737 0.082 -0.548 0.033 With SBP/DBP/HR
ObesityTRUE -0.738 0.155 -4.771 0.000 -1.042 -0.435 Without SBP/DBP/HR
packyrs 0.023 0.004 6.047 0.000 0.015 0.030 With SBP/DBP/HR
packyrs 0.022 0.004 5.458 0.000 0.014 0.029 Without SBP/DBP/HR
poly(Age, 2)1 -68.835 8.358 -8.235 0.000 -85.218 -52.452 With SBP/DBP/HR
poly(Age, 2)1 -24.680 7.938 -3.109 0.002 -40.238 -9.122 Without SBP/DBP/HR
poly(Age, 2)2 -106.512 7.248 -14.696 0.000 -120.718 -92.306 With SBP/DBP/HR
poly(Age, 2)2 -113.329 7.564 -14.983 0.000 -128.155 -98.503 Without SBP/DBP/HR
PriorMed 0.550 1.212 0.454 0.650 -1.825 2.924 With SBP/DBP/HR
PriorMed 0.815 1.268 0.643 0.520 -1.669 3.300 Without SBP/DBP/HR
pulse_rate 0.110 0.004 27.838 0.000 0.102 0.118 With SBP/DBP/HR
sbp 0.067 0.003 19.635 0.000 0.061 0.074 With SBP/DBP/HR
SexMale 0.450 0.095 4.754 0.000 0.264 0.635 With SBP/DBP/HR
SexMale 0.521 0.096 5.433 0.000 0.333 0.710 Without SBP/DBP/HR
get_pretty_fit_forest_plot(digoxin.fits.df) ->p
p

digoxin.fits.df %>% 
  get_fit_glance
generate_table.self.reported(digoxin.df, "Digoxin")
Characteristic Digoxin, N = 361 No Digoxin, N = 27,5101 p-value2
Cardiac Age gap 1.5 (-4.9, 6.7) 0.2 (-5.3, 5.3) 0.5
Sex <0.001
Female 8 (22%) 13,829 (50%)
Male 28 (78%) 13,681 (50%)
Age 71 (66, 75) 65 (58, 70) <0.001
Packs year of smoking 0 (0, 8) 0 (0, 3) 0.6
Alcohol is g/day consumed 2 (0, 17) 4 (0, 15) 0.7
Hypertension 23 (64%) 9,175 (33%) <0.001
Obesity 12 (33%) 5,663 (21%) 0.059
Diabetes Mellitus 13 (36%) 1,970 (7.2%) <0.001
Coronary Artery Disease 8 (22%) 2,100 (7.6%) 0.005
Hypercholesterolemia 12 (33%) 6,279 (23%) 0.13
Heart Failure 14 (39%) 398 (1.4%) <0.001
dbp 77 (71, 88) 78 (72, 86) >0.9
sbp 136 (124, 156) 138 (126, 150) 0.8
pulse_rate 74 (66, 82) 68 (61, 76) 0.006
bmi 27.3 (23.9, 31.7) 26.3 (23.8, 29.3) 0.3
1 Median (IQR); n (%)
2 Wilcoxon rank sum test; Pearson's Chi-squared test; Fisher's exact test
digoxin.df %>% 
  get_stratified_age_gap_histogram("Digoxin")

digoxin.df %>% 
  get_stratified_age_gap_quantiles("Digoxin")

0.6.1 Lasso

digoxin.glmnet.cv <- fits.glm[["Digoxin"]]
plot(digoxin.glmnet.cv) 

coef(digoxin.glmnet.cv, c(digoxin.glmnet.cv$lambda.min,
                   digoxin.glmnet.cv$lambda.1se))
## 17 x 2 sparse Matrix of class "dgCMatrix"
##                                    s1            s2
## (Intercept)             -2.330190e-16 -1.012851e-16
## SID                      1.638825e-03  .           
## SexMale                  2.340433e-02  .           
## Age                     -4.899890e-02  .           
## packyrs                  3.546793e-02  4.173688e-03
## alcoholintakegpd         3.335993e-03  .           
## PriorMed                 2.639928e-04  .           
## HypertensionTRUE         3.987529e-02  1.019900e-02
## ObesityTRUE             -1.031775e-02  .           
## `Diabetes Mellitus`TRUE  2.092399e-02  .           
## CADTRUE                  1.241705e-02  .           
## HypercholTRUE           -6.457367e-03  .           
## `Heart Failure`TRUE      .             .           
## bmi                     -8.489514e-02 -3.159110e-02
## sbp                      1.555273e-01  1.167419e-01
## dbp                      1.232406e-01  1.224064e-01
## pulse_rate               1.652914e-01  1.278304e-01

0.7 Beta Blocker

BB.df <- dfs %>% 
  filter(Drug=="BB") %>% 
  select(-Drug)
BB.fits.df <- fits.df %>% 
  filter(Drug=="BB")
get_pretty_fit_table(BB.fits.df, "Beta Blocker")
Beta Blocker: Coefficients from linear models
term estimate std.error statistic p.value conf.low conf.high Adjustment
(Intercept) -20.673 0.519 -39.825 0.000 -21.690 -19.655 With SBP/DBP/HR
(Intercept) -0.893 0.359 -2.486 0.013 -1.596 -0.189 Without SBP/DBP/HR
Diabetes MellitusTRUE 0.649 0.176 3.681 0.000 0.304 0.995 With SBP/DBP/HR
Diabetes MellitusTRUE 0.620 0.183 3.385 0.001 0.261 0.980 Without SBP/DBP/HR
Heart FailureTRUE 0.015 0.371 0.041 0.967 -0.713 0.743 With SBP/DBP/HR
Heart FailureTRUE -0.001 0.388 -0.002 0.999 -0.762 0.761 Without SBP/DBP/HR
alcoholintakegpd 0.001 0.003 0.293 0.770 -0.004 0.006 With SBP/DBP/HR
alcoholintakegpd 0.006 0.003 2.355 0.019 0.001 0.011 Without SBP/DBP/HR
bmi -0.149 0.014 -10.691 0.000 -0.176 -0.122 With SBP/DBP/HR
bmi 0.001 0.014 0.046 0.963 -0.027 0.029 Without SBP/DBP/HR
CADTRUE 0.281 0.185 1.524 0.128 -0.081 0.643 With SBP/DBP/HR
CADTRUE -0.235 0.193 -1.219 0.223 -0.613 0.143 Without SBP/DBP/HR
dbp 0.087 0.006 14.008 0.000 0.075 0.100 With SBP/DBP/HR
HypercholTRUE -0.158 0.112 -1.416 0.157 -0.378 0.061 With SBP/DBP/HR
HypercholTRUE -0.203 0.117 -1.733 0.083 -0.432 0.027 Without SBP/DBP/HR
HypertensionTRUE 0.609 0.103 5.925 0.000 0.408 0.811 With SBP/DBP/HR
HypertensionTRUE 1.868 0.104 17.961 0.000 1.664 2.072 Without SBP/DBP/HR
ObesityTRUE -0.256 0.148 -1.728 0.084 -0.547 0.034 With SBP/DBP/HR
ObesityTRUE -0.734 0.155 -4.744 0.000 -1.037 -0.431 Without SBP/DBP/HR
packyrs 0.023 0.004 6.047 0.000 0.015 0.030 With SBP/DBP/HR
packyrs 0.022 0.004 5.450 0.000 0.014 0.029 Without SBP/DBP/HR
poly(Age, 2)1 -70.335 8.370 -8.404 0.000 -86.740 -53.930 With SBP/DBP/HR
poly(Age, 2)1 -23.089 7.942 -2.907 0.004 -38.656 -7.522 Without SBP/DBP/HR
poly(Age, 2)2 -106.876 7.247 -14.748 0.000 -121.080 -92.672 With SBP/DBP/HR
poly(Age, 2)2 -112.698 7.562 -14.903 0.000 -127.520 -97.876 Without SBP/DBP/HR
PriorMed 0.606 0.190 3.182 0.001 0.233 0.979 With SBP/DBP/HR
PriorMed -0.818 0.196 -4.165 0.000 -1.203 -0.433 Without SBP/DBP/HR
pulse_rate 0.112 0.004 28.017 0.000 0.104 0.120 With SBP/DBP/HR
sbp 0.068 0.003 19.772 0.000 0.061 0.075 With SBP/DBP/HR
SexMale 0.455 0.095 4.806 0.000 0.269 0.640 With SBP/DBP/HR
SexMale 0.523 0.096 5.450 0.000 0.335 0.711 Without SBP/DBP/HR
get_pretty_fit_forest_plot(BB.fits.df) ->p
p

BB.fits.df %>% 
  get_fit_glance
generate_table.self.reported(BB.df, "BB")
Characteristic BB, N = 1,9181 No BB, N = 25,6281 p-value2
Cardiac Age gap 0.0 (-5.3, 5.0) 0.2 (-5.3, 5.4) 0.2
Sex <0.001
Female 681 (36%) 13,156 (51%)
Male 1,237 (64%) 12,472 (49%)
Age 69 (63, 72) 64 (58, 69) <0.001
Packs year of smoking 0 (0, 8) 0 (0, 3) <0.001
Alcohol is g/day consumed 4 (0, 17) 4 (0, 15) 0.3
Hypertension 1,262 (66%) 7,936 (31%) <0.001
Obesity 587 (31%) 5,088 (20%) <0.001
Diabetes Mellitus 315 (16%) 1,668 (6.5%) <0.001
Coronary Artery Disease 843 (44%) 1,265 (4.9%) <0.001
Hypercholesterolemia 935 (49%) 5,356 (21%) <0.001
Heart Failure 171 (8.9%) 241 (0.9%) <0.001
dbp 76 (70, 84) 79 (72, 86) <0.001
sbp 138 (126, 152) 138 (126, 150) 0.12
pulse_rate 61 (55, 69) 68 (62, 76) <0.001
bmi 27.7 (25.1, 30.9) 26.2 (23.7, 29.1) <0.001
1 Median (IQR); n (%)
2 Wilcoxon rank sum test; Pearson's Chi-squared test
BB.df %>% 
 get_stratified_age_gap_histogram("Beta Blockers")

BB.df %>% 
 get_stratified_age_gap_quantiles("Beta Blockers")

0.7.1 Lasso

BB.glmnet.cv <- fits.glm[["BB"]]
plot(BB.glmnet.cv) 

coef(BB.glmnet.cv, c(BB.glmnet.cv$lambda.min,
                   BB.glmnet.cv$lambda.1se))
## 17 x 2 sparse Matrix of class "dgCMatrix"
##                                    s1            s2
## (Intercept)             -2.424344e-16 -1.012851e-16
## SID                      1.982979e-03  .           
## SexMale                  2.395217e-02  .           
## Age                     -5.080671e-02  .           
## packyrs                  3.581281e-02  4.173688e-03
## alcoholintakegpd         3.411826e-03  .           
## PriorMed                 1.750507e-02  .           
## HypertensionTRUE         3.782778e-02  1.019900e-02
## ObesityTRUE             -1.044448e-02  .           
## `Diabetes Mellitus`TRUE  2.086409e-02  .           
## CADTRUE                  7.322854e-03  .           
## HypercholTRUE           -7.898300e-03  .           
## `Heart Failure`TRUE      .             .           
## bmi                     -8.685689e-02 -3.159110e-02
## sbp                      1.572566e-01  1.167419e-01
## dbp                      1.233614e-01  1.224064e-01
## pulse_rate               1.682552e-01  1.278304e-01

0.8 ACEi

ACEi.df <- dfs %>% 
  filter(Drug=="ACEi") %>% 
  select(-Drug)
ACEi.fits.df <- fits.df %>% 
  filter(Drug=="ACEi")
get_pretty_fit_table(ACEi.fits.df, "ACEi")
ACEi: Coefficients from linear models
term estimate std.error statistic p.value conf.low conf.high Adjustment
(Intercept) -20.514 0.517 -39.675 0.000 -21.527 -19.501 With SBP/DBP/HR
(Intercept) -0.867 0.359 -2.415 0.016 -1.571 -0.164 Without SBP/DBP/HR
Diabetes MellitusTRUE 0.667 0.177 3.780 0.000 0.321 1.013 With SBP/DBP/HR
Diabetes MellitusTRUE 0.629 0.184 3.428 0.001 0.269 0.989 Without SBP/DBP/HR
Heart FailureTRUE 0.112 0.371 0.303 0.762 -0.615 0.839 With SBP/DBP/HR
Heart FailureTRUE -0.069 0.388 -0.178 0.858 -0.830 0.691 Without SBP/DBP/HR
alcoholintakegpd 0.001 0.003 0.328 0.743 -0.004 0.006 With SBP/DBP/HR
alcoholintakegpd 0.006 0.003 2.344 0.019 0.001 0.011 Without SBP/DBP/HR
bmi -0.147 0.014 -10.520 0.000 -0.174 -0.119 With SBP/DBP/HR
bmi -0.001 0.014 -0.064 0.949 -0.029 0.027 Without SBP/DBP/HR
CADTRUE 0.463 0.178 2.600 0.009 0.114 0.812 With SBP/DBP/HR
CADTRUE -0.423 0.185 -2.284 0.022 -0.785 -0.060 Without SBP/DBP/HR
dbp 0.087 0.006 13.980 0.000 0.075 0.099 With SBP/DBP/HR
HypercholTRUE -0.139 0.112 -1.242 0.214 -0.358 0.080 With SBP/DBP/HR
HypercholTRUE -0.215 0.117 -1.838 0.066 -0.444 0.014 Without SBP/DBP/HR
HypertensionTRUE 0.663 0.107 6.226 0.000 0.454 0.872 With SBP/DBP/HR
HypertensionTRUE 1.894 0.108 17.524 0.000 1.682 2.106 Without SBP/DBP/HR
ObesityTRUE -0.257 0.148 -1.732 0.083 -0.547 0.034 With SBP/DBP/HR
ObesityTRUE -0.733 0.155 -4.739 0.000 -1.037 -0.430 Without SBP/DBP/HR
packyrs 0.023 0.004 6.049 0.000 0.015 0.030 With SBP/DBP/HR
packyrs 0.022 0.004 5.473 0.000 0.014 0.029 Without SBP/DBP/HR
poly(Age, 2)1 -68.774 8.357 -8.230 0.000 -85.154 -52.394 With SBP/DBP/HR
poly(Age, 2)1 -24.893 7.937 -3.136 0.002 -40.449 -9.336 Without SBP/DBP/HR
poly(Age, 2)2 -106.492 7.248 -14.693 0.000 -120.698 -92.286 With SBP/DBP/HR
poly(Age, 2)2 -113.511 7.563 -15.008 0.000 -128.336 -98.687 Without SBP/DBP/HR
PriorMed -0.044 0.168 -0.260 0.795 -0.373 0.286 With SBP/DBP/HR
PriorMed -0.420 0.176 -2.390 0.017 -0.764 -0.075 Without SBP/DBP/HR
pulse_rate 0.110 0.004 27.843 0.000 0.102 0.118 With SBP/DBP/HR
sbp 0.067 0.003 19.621 0.000 0.061 0.074 With SBP/DBP/HR
SexMale 0.452 0.095 4.766 0.000 0.266 0.637 With SBP/DBP/HR
SexMale 0.533 0.096 5.551 0.000 0.345 0.722 Without SBP/DBP/HR
get_pretty_fit_forest_plot(ACEi.fits.df) ->p
p

ACEi.fits.df %>% 
  get_fit_glance
generate_table.self.reported(ACEi.df, "ACEi")
Characteristic ACEi, N = 2,4121 No ACEi, N = 25,1341 p-value2
Cardiac Age gap 0.7 (-4.6, 5.9) 0.1 (-5.4, 5.3) <0.001
Sex <0.001
Female 764 (32%) 13,073 (52%)
Male 1,648 (68%) 12,061 (48%)
Age 67 (61, 71) 64 (58, 70) <0.001
Packs year of smoking 0 (0, 7) 0 (0, 3) <0.001
Alcohol is g/day consumed 4 (0, 18) 4 (0, 15) 0.004
Hypertension 2,075 (86%) 7,123 (28%) <0.001
Obesity 776 (32%) 4,899 (19%) <0.001
Diabetes Mellitus 446 (18%) 1,537 (6.1%) <0.001
Coronary Artery Disease 621 (26%) 1,487 (5.9%) <0.001
Hypercholesterolemia 1,086 (45%) 5,205 (21%) <0.001
Heart Failure 145 (6.0%) 267 (1.1%) <0.001
dbp 80 (72, 86) 78 (72, 85) <0.001
sbp 142 (131, 154) 137 (126, 150) <0.001
pulse_rate 68 (60, 76) 68 (61, 76) 0.6
bmi 27.9 (25.1, 30.9) 26.1 (23.7, 29.1) <0.001
1 Median (IQR); n (%)
2 Wilcoxon rank sum test; Pearson's Chi-squared test
ACEi.df %>% 
  get_stratified_age_gap_histogram("ACEi")

ACEi.df %>% 
   get_stratified_age_gap_quantiles("ACEi")

0.8.1 Lasso

ACEi.glmnet.cv <- fits.glm[["ACEi"]]
plot(ACEi.glmnet.cv) 

coef(ACEi.glmnet.cv, c(ACEi.glmnet.cv$lambda.min,
                   ACEi.glmnet.cv$lambda.1se))
## 17 x 2 sparse Matrix of class "dgCMatrix"
##                                    s1            s2
## (Intercept)             -2.286956e-16 -9.385681e-17
## SID                      8.920302e-04  .           
## SexMale                  2.276959e-02  .           
## Age                     -4.767750e-02  .           
## packyrs                  3.479136e-02  8.410991e-04
## alcoholintakegpd         2.885660e-03  .           
## PriorMed                 .             .           
## HypertensionTRUE         3.907782e-02  7.401584e-03
## ObesityTRUE             -9.937072e-03  .           
## `Diabetes Mellitus`TRUE  2.011325e-02  .           
## CADTRUE                  1.147156e-02  .           
## HypercholTRUE           -5.361039e-03  .           
## `Heart Failure`TRUE      .             .           
## bmi                     -8.367754e-02 -2.634601e-02
## sbp                      1.545082e-01  1.151769e-01
## dbp                      1.233096e-01  1.201523e-01
## pulse_rate               1.643223e-01  1.247856e-01

0.9 ARB

ARB.df <- dfs %>% 
  filter(Drug=="ARB") %>% 
  select(-Drug)
ARB.fits.df <- fits.df %>% 
  filter(Drug=="ARB")
get_pretty_fit_table(ARB.fits.df, "ARB")
ARB: Coefficients from linear models
term estimate std.error statistic p.value conf.low conf.high Adjustment
(Intercept) -20.512 0.517 -39.681 0.000 -21.525 -19.498 With SBP/DBP/HR
(Intercept) -0.862 0.359 -2.397 0.017 -1.566 -0.157 Without SBP/DBP/HR
Diabetes MellitusTRUE 0.656 0.177 3.718 0.000 0.310 1.002 With SBP/DBP/HR
Diabetes MellitusTRUE 0.607 0.184 3.309 0.001 0.248 0.967 Without SBP/DBP/HR
Heart FailureTRUE 0.099 0.370 0.267 0.789 -0.627 0.825 With SBP/DBP/HR
Heart FailureTRUE -0.123 0.388 -0.317 0.751 -0.882 0.637 Without SBP/DBP/HR
alcoholintakegpd 0.001 0.003 0.325 0.745 -0.004 0.006 With SBP/DBP/HR
alcoholintakegpd 0.006 0.003 2.333 0.020 0.001 0.011 Without SBP/DBP/HR
bmi -0.147 0.014 -10.559 0.000 -0.175 -0.120 With SBP/DBP/HR
bmi -0.001 0.014 -0.062 0.951 -0.029 0.027 Without SBP/DBP/HR
CADTRUE 0.450 0.176 2.550 0.011 0.104 0.796 With SBP/DBP/HR
CADTRUE -0.483 0.183 -2.632 0.008 -0.842 -0.123 Without SBP/DBP/HR
dbp 0.087 0.006 14.004 0.000 0.075 0.100 With SBP/DBP/HR
HypercholTRUE -0.143 0.112 -1.275 0.202 -0.362 0.077 With SBP/DBP/HR
HypercholTRUE -0.226 0.117 -1.934 0.053 -0.455 0.003 Without SBP/DBP/HR
HypertensionTRUE 0.628 0.106 5.942 0.000 0.421 0.836 With SBP/DBP/HR
HypertensionTRUE 1.827 0.107 17.005 0.000 1.616 2.037 Without SBP/DBP/HR
ObesityTRUE -0.255 0.148 -1.723 0.085 -0.546 0.035 With SBP/DBP/HR
ObesityTRUE -0.738 0.155 -4.770 0.000 -1.041 -0.435 Without SBP/DBP/HR
packyrs 0.023 0.004 6.059 0.000 0.016 0.030 With SBP/DBP/HR
packyrs 0.022 0.004 5.456 0.000 0.014 0.029 Without SBP/DBP/HR
poly(Age, 2)1 -68.999 8.360 -8.253 0.000 -85.386 -52.612 With SBP/DBP/HR
poly(Age, 2)1 -24.507 7.942 -3.086 0.002 -40.073 -8.940 Without SBP/DBP/HR
poly(Age, 2)2 -106.467 7.247 -14.692 0.000 -120.671 -92.263 With SBP/DBP/HR
poly(Age, 2)2 -113.256 7.563 -14.974 0.000 -128.080 -98.431 Without SBP/DBP/HR
PriorMed 0.183 0.195 0.937 0.349 -0.200 0.565 With SBP/DBP/HR
PriorMed -0.059 0.204 -0.289 0.772 -0.459 0.341 Without SBP/DBP/HR
pulse_rate 0.110 0.004 27.848 0.000 0.103 0.118 With SBP/DBP/HR
sbp 0.067 0.003 19.632 0.000 0.061 0.074 With SBP/DBP/HR
SexMale 0.452 0.095 4.772 0.000 0.266 0.637 With SBP/DBP/HR
SexMale 0.521 0.096 5.432 0.000 0.333 0.710 Without SBP/DBP/HR
get_pretty_fit_forest_plot(ARB.fits.df) ->p
p

ARB.fits.df %>% 
  get_fit_glance
generate_table.self.reported(ARB.df, "ARB")
Characteristic ARB, N = 1,6421 No ARB, N = 25,9041 p-value2
Cardiac Age gap 1.2 (-4.1, 6.3) 0.1 (-5.4, 5.3) <0.001
Sex <0.001
Female 712 (43%) 13,125 (51%)
Male 930 (57%) 12,779 (49%)
Age 68 (62, 72) 64 (58, 70) <0.001
Packs year of smoking 0 (0, 4) 0 (0, 3) 0.4
Alcohol is g/day consumed 4 (0, 18) 4 (0, 15) 0.063
Hypertension 1,535 (93%) 7,663 (30%) <0.001
Obesity 568 (35%) 5,107 (20%) <0.001
Diabetes Mellitus 315 (19%) 1,668 (6.4%) <0.001
Coronary Artery Disease 295 (18%) 1,813 (7.0%) <0.001
Hypercholesterolemia 708 (43%) 5,583 (22%) <0.001
Heart Failure 67 (4.1%) 345 (1.3%) <0.001
dbp 80 (74, 87) 78 (72, 85) <0.001
sbp 144 (134, 156) 137 (126, 150) <0.001
pulse_rate 69 (62, 78) 68 (60, 76) <0.001
bmi 28.3 (25.9, 31.4) 26.1 (23.7, 29.1) <0.001
1 Median (IQR); n (%)
2 Wilcoxon rank sum test; Pearson's Chi-squared test
ARB.df %>% 
  get_stratified_age_gap_histogram("ARB")

ARB.df %>% 
    get_stratified_age_gap_quantiles("ARB")

0.9.1 Lasso

ARB.glmnet.cv <- fits.glm[["ARB"]]
plot(ARB.glmnet.cv) 

coef(ARB.glmnet.cv, c(ARB.glmnet.cv$lambda.min,
                   ARB.glmnet.cv$lambda.1se))
## 17 x 2 sparse Matrix of class "dgCMatrix"
##                                    s1            s2
## (Intercept)             -2.314783e-16 -1.080653e-16
## SID                      1.962549e-03  .           
## SexMale                  2.374022e-02  .           
## Age                     -4.971222e-02  .           
## packyrs                  3.580341e-02  7.207680e-03
## alcoholintakegpd         3.515135e-03  .           
## PriorMed                 4.828414e-03  .           
## HypertensionTRUE         3.879835e-02  1.273594e-02
## ObesityTRUE             -1.039479e-02  .           
## `Diabetes Mellitus`TRUE  2.102259e-02  .           
## CADTRUE                  1.259680e-02  .           
## HypercholTRUE           -7.020339e-03  .           
## `Heart Failure`TRUE      .             .           
## bmi                     -8.573188e-02 -3.636707e-02
## sbp                      1.559629e-01  1.182037e-01
## dbp                      1.233456e-01  1.244400e-01
## pulse_rate               1.657049e-01  1.306085e-01

0.10 CCB

CCB.df <- dfs %>% 
  filter(Drug=="CCB") %>% 
  select(-Drug)
CCB.fits.df <- fits.df %>% 
  filter(Drug=="CCB")
get_pretty_fit_table(CCB.fits.df, "CCB")
CCB: Coefficients from linear models
term estimate std.error statistic p.value conf.low conf.high Adjustment
(Intercept) -20.491 0.517 -39.635 0.000 -21.505 -19.478 With SBP/DBP/HR
(Intercept) -0.871 0.359 -2.427 0.015 -1.575 -0.168 Without SBP/DBP/HR
Diabetes MellitusTRUE 0.668 0.176 3.786 0.000 0.322 1.013 With SBP/DBP/HR
Diabetes MellitusTRUE 0.616 0.183 3.359 0.001 0.256 0.975 Without SBP/DBP/HR
Heart FailureTRUE 0.090 0.370 0.242 0.808 -0.636 0.816 With SBP/DBP/HR
Heart FailureTRUE -0.158 0.387 -0.407 0.684 -0.917 0.602 Without SBP/DBP/HR
alcoholintakegpd 0.001 0.003 0.356 0.722 -0.004 0.006 With SBP/DBP/HR
alcoholintakegpd 0.006 0.003 2.383 0.017 0.001 0.011 Without SBP/DBP/HR
bmi -0.146 0.014 -10.485 0.000 -0.173 -0.119 With SBP/DBP/HR
bmi -0.001 0.014 -0.043 0.965 -0.029 0.027 Without SBP/DBP/HR
CADTRUE 0.450 0.176 2.553 0.011 0.105 0.796 With SBP/DBP/HR
CADTRUE -0.496 0.183 -2.704 0.007 -0.855 -0.136 Without SBP/DBP/HR
dbp 0.087 0.006 13.866 0.000 0.074 0.099 With SBP/DBP/HR
HypercholTRUE -0.137 0.112 -1.225 0.221 -0.356 0.082 With SBP/DBP/HR
HypercholTRUE -0.219 0.117 -1.873 0.061 -0.448 0.010 Without SBP/DBP/HR
HypertensionTRUE 0.749 0.111 6.726 0.000 0.531 0.967 With SBP/DBP/HR
HypertensionTRUE 2.003 0.113 17.738 0.000 1.781 2.224 Without SBP/DBP/HR
ObesityTRUE -0.259 0.148 -1.750 0.080 -0.550 0.031 With SBP/DBP/HR
ObesityTRUE -0.740 0.155 -4.782 0.000 -1.043 -0.437 Without SBP/DBP/HR
packyrs 0.023 0.004 6.040 0.000 0.015 0.030 With SBP/DBP/HR
packyrs 0.022 0.004 5.461 0.000 0.014 0.029 Without SBP/DBP/HR
poly(Age, 2)1 -67.735 8.370 -8.092 0.000 -84.141 -51.329 With SBP/DBP/HR
poly(Age, 2)1 -22.451 7.952 -2.823 0.005 -38.037 -6.865 Without SBP/DBP/HR
poly(Age, 2)2 -106.555 7.247 -14.704 0.000 -120.759 -92.352 With SBP/DBP/HR
poly(Age, 2)2 -113.337 7.561 -14.989 0.000 -128.157 -98.517 Without SBP/DBP/HR
PriorMed -0.337 0.162 -2.079 0.038 -0.655 -0.019 With SBP/DBP/HR
PriorMed -0.685 0.169 -4.051 0.000 -1.017 -0.354 Without SBP/DBP/HR
pulse_rate 0.111 0.004 27.901 0.000 0.103 0.118 With SBP/DBP/HR
sbp 0.067 0.003 19.609 0.000 0.061 0.074 With SBP/DBP/HR
SexMale 0.461 0.095 4.863 0.000 0.275 0.647 With SBP/DBP/HR
SexMale 0.536 0.096 5.587 0.000 0.348 0.725 Without SBP/DBP/HR
get_pretty_fit_forest_plot(CCB.fits.df) ->p
p

CCB.fits.df %>% 
  get_fit_glance
generate_table.self.reported(CCB.df, "CCB")
Characteristic CCB, N = 2,7741 No CCB, N = 24,7721 p-value2
Cardiac Age gap 0.9 (-4.0, 5.8) 0.1 (-5.4, 5.3) <0.001
Sex <0.001
Female 1,017 (37%) 12,820 (52%)
Male 1,757 (63%) 11,952 (48%)
Age 68 (63, 72) 64 (58, 69) <0.001
Packs year of smoking 0 (0, 6) 0 (0, 3) 0.017
Alcohol is g/day consumed 5 (0, 19) 3 (0, 15) <0.001
Hypertension 2,657 (96%) 6,541 (26%) <0.001
Obesity 822 (30%) 4,853 (20%) <0.001
Diabetes Mellitus 390 (14%) 1,593 (6.4%) <0.001
Coronary Artery Disease 328 (12%) 1,780 (7.2%) <0.001
Hypercholesterolemia 1,109 (40%) 5,182 (21%) <0.001
Heart Failure 48 (1.7%) 364 (1.5%) 0.3
dbp 80 (74, 86) 78 (72, 85) <0.001
sbp 144 (134, 155) 137 (125, 150) <0.001
pulse_rate 70 (62, 78) 68 (60, 76) <0.001
bmi 27.7 (25.0, 30.7) 26.1 (23.7, 29.1) <0.001
1 Median (IQR); n (%)
2 Wilcoxon rank sum test; Pearson's Chi-squared test
CCB.df %>% 
  get_stratified_age_gap_histogram("CCB")

CCB.df %>% 
  get_stratified_age_gap_quantiles("CCB")

0.10.1 Lasso

CCB.glmnet.cv <- fits.glm[["CCB"]]
plot(CCB.glmnet.cv) 

coef(CCB.glmnet.cv, c(CCB.glmnet.cv$lambda.min,
                   CCB.glmnet.cv$lambda.1se))
## 17 x 2 sparse Matrix of class "dgCMatrix"
##                                    s1            s2
## (Intercept)             -2.295597e-16 -1.213257e-16
## SID                      1.521459e-03  .           
## SexMale                  2.394914e-02  1.778284e-03
## Age                     -4.834152e-02 -4.750819e-03
## packyrs                  3.542791e-02  1.261464e-02
## alcoholintakegpd         3.484559e-03  .           
## PriorMed                -1.058849e-02  .           
## HypertensionTRUE         4.446964e-02  1.773942e-02
## ObesityTRUE             -1.040865e-02  .           
## `Diabetes Mellitus`TRUE  2.099499e-02  .           
## CADTRUE                  1.218835e-02  .           
## HypercholTRUE           -6.316453e-03  .           
## `Heart Failure`TRUE      .             .           
## bmi                     -8.464660e-02 -4.518251e-02
## sbp                      1.553599e-01  1.228784e-01
## dbp                      1.225816e-01  1.258928e-01
## pulse_rate               1.656166e-01  1.360434e-01

0.11 Diuretics

diuretics.df <- dfs %>% 
  filter(Drug=="Diuretics") %>% 
  select(-Drug)
diuretics.fits.df <- fits.df %>% 
  filter(Drug=="Diuretics")
get_pretty_fit_table(diuretics.fits.df, "Diuretics")
Diuretics: Coefficients from linear models
term estimate std.error statistic p.value conf.low conf.high Adjustment
(Intercept) -20.518 0.517 -39.695 0.000 -21.531 -19.505 With SBP/DBP/HR
(Intercept) -0.874 0.359 -2.433 0.015 -1.578 -0.170 Without SBP/DBP/HR
Diabetes MellitusTRUE 0.664 0.176 3.763 0.000 0.318 1.009 With SBP/DBP/HR
Diabetes MellitusTRUE 0.608 0.183 3.319 0.001 0.249 0.968 Without SBP/DBP/HR
Heart FailureTRUE 0.093 0.371 0.249 0.803 -0.635 0.820 With SBP/DBP/HR
Heart FailureTRUE -0.089 0.388 -0.230 0.818 -0.851 0.672 Without SBP/DBP/HR
alcoholintakegpd 0.001 0.003 0.329 0.742 -0.004 0.006 With SBP/DBP/HR
alcoholintakegpd 0.006 0.003 2.323 0.020 0.001 0.011 Without SBP/DBP/HR
bmi -0.147 0.014 -10.537 0.000 -0.174 -0.120 With SBP/DBP/HR
bmi 0.000 0.014 -0.022 0.982 -0.028 0.028 Without SBP/DBP/HR
CADTRUE 0.456 0.176 2.585 0.010 0.110 0.801 With SBP/DBP/HR
CADTRUE -0.483 0.183 -2.634 0.008 -0.842 -0.123 Without SBP/DBP/HR
dbp 0.087 0.006 13.991 0.000 0.075 0.100 With SBP/DBP/HR
HypercholTRUE -0.142 0.112 -1.269 0.204 -0.361 0.077 With SBP/DBP/HR
HypercholTRUE -0.222 0.117 -1.900 0.057 -0.452 0.007 Without SBP/DBP/HR
HypertensionTRUE 0.643 0.105 6.133 0.000 0.437 0.848 With SBP/DBP/HR
HypertensionTRUE 1.849 0.106 17.403 0.000 1.641 2.058 Without SBP/DBP/HR
ObesityTRUE -0.257 0.148 -1.733 0.083 -0.547 0.034 With SBP/DBP/HR
ObesityTRUE -0.738 0.155 -4.768 0.000 -1.041 -0.435 Without SBP/DBP/HR
packyrs 0.023 0.004 6.045 0.000 0.015 0.030 With SBP/DBP/HR
packyrs 0.022 0.004 5.468 0.000 0.014 0.029 Without SBP/DBP/HR
poly(Age, 2)1 -68.955 8.366 -8.242 0.000 -85.352 -52.557 With SBP/DBP/HR
poly(Age, 2)1 -24.164 7.944 -3.042 0.002 -39.734 -8.595 Without SBP/DBP/HR
poly(Age, 2)2 -106.461 7.247 -14.691 0.000 -120.666 -92.257 With SBP/DBP/HR
poly(Age, 2)2 -113.260 7.563 -14.975 0.000 -128.084 -98.436 Without SBP/DBP/HR
PriorMed 0.113 0.221 0.511 0.610 -0.320 0.545 With SBP/DBP/HR
PriorMed -0.289 0.231 -1.254 0.210 -0.741 0.163 Without SBP/DBP/HR
pulse_rate 0.110 0.004 27.846 0.000 0.103 0.118 With SBP/DBP/HR
sbp 0.067 0.003 19.637 0.000 0.061 0.074 With SBP/DBP/HR
SexMale 0.452 0.095 4.774 0.000 0.266 0.638 With SBP/DBP/HR
SexMale 0.517 0.096 5.381 0.000 0.329 0.705 Without SBP/DBP/HR
get_pretty_fit_forest_plot(diuretics.fits.df) ->p
p

diuretics.fits.df %>% 
  get_fit_glance
generate_table.self.reported(diuretics.df, "diuretics")
Characteristic diuretics, N = 1,2301 No diuretics, N = 26,3161 p-value2
Cardiac Age gap 1.0 (-3.9, 5.8) 0.1 (-5.4, 5.3) <0.001
Sex 0.6
Female 608 (49%) 13,229 (50%)
Male 622 (51%) 13,087 (50%)
Age 68 (63, 72) 64 (58, 70) <0.001
Packs year of smoking 0 (0, 6) 0 (0, 3) 0.019
Alcohol is g/day consumed 3 (0, 14) 4 (0, 15) 0.003
Hypertension 1,148 (93%) 8,050 (31%) <0.001
Obesity 447 (36%) 5,228 (20%) <0.001
Diabetes Mellitus 202 (16%) 1,781 (6.8%) <0.001
Coronary Artery Disease 202 (16%) 1,906 (7.2%) <0.001
Hypercholesterolemia 546 (44%) 5,745 (22%) <0.001
Heart Failure 83 (6.7%) 329 (1.3%) <0.001
dbp 80 (73, 86) 78 (72, 85) <0.001
sbp 143 (131, 155) 138 (126, 150) <0.001
pulse_rate 70 (62, 79) 68 (61, 76) <0.001
bmi 28.5 (25.7, 31.8) 26.2 (23.7, 29.2) <0.001
1 Median (IQR); n (%)
2 Wilcoxon rank sum test; Pearson's Chi-squared test
diuretics.df %>% 
  get_stratified_age_gap_histogram("Diuretics")

diuretics.df %>% 
 get_stratified_age_gap_quantiles("Diuretics")

0.11.1 Lasso

diuretics.glmnet.cv <- fits.glm[["Diuretics"]]
plot(diuretics.glmnet.cv) 

coef(diuretics.glmnet.cv, c(diuretics.glmnet.cv$lambda.min,
                   diuretics.glmnet.cv$lambda.1se))
## 17 x 2 sparse Matrix of class "dgCMatrix"
##                                    s1            s2
## (Intercept)             -2.278847e-16 -1.144220e-16
## SID                      8.914631e-04  .           
## SexMale                  2.281645e-02  .           
## Age                     -4.776635e-02 -3.901188e-04
## packyrs                  3.477911e-02  1.000863e-02
## alcoholintakegpd         2.893804e-03  .           
## PriorMed                 1.147081e-03  .           
## HypertensionTRUE         3.879576e-02  1.517539e-02
## ObesityTRUE             -9.901109e-03  .           
## `Diabetes Mellitus`TRUE  2.008850e-02  .           
## CADTRUE                  1.145429e-02  .           
## HypercholTRUE           -5.394407e-03  .           
## `Heart Failure`TRUE      .             .           
## bmi                     -8.377949e-02 -4.076007e-02
## sbp                      1.545863e-01  1.195392e-01
## dbp                      1.232900e-01  1.262449e-01
## pulse_rate               1.643293e-01  1.331395e-01

0.12 Self-reported drugs used

read_csv("../data/Derived/self_reported_drugs_used.csv")
## Rows: 79 Columns: 2
## ── Column specification ──────────────────────────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): meaning, Drug
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.